package com.aacar.controller.common;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.aacar.dto.DictionaryDto;
import com.aacar.dto.Header;
import com.aacar.service.DictionaryService;
import com.aacar.utils.ResultInfoUtil;
import com.aacar.vo.DictionaryVo;
import com.alibaba.fastjson.JSON;

/**
 * 字典管理
 * @author wangh
 *
 */
@RestController
@RequestMapping("/dictionary")
public class DictionaryController {
	
	private Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
	private DictionaryService dictionaryService;
	
	@RequestMapping(value="/getValueByPreAndKey/0", method = RequestMethod.POST)
	@ResponseBody
	public Object getValueByPreAndKey(@RequestHeader(value="mobilehead") String mobilehead,@RequestBody DictionaryDto dto) {
		String value = this.dictionaryService.getValueByPreAndKey(dto.getPreType(), dto.getKey());
		Header header = null;
		if(null != mobilehead) {
			header = JSON.parseObject(mobilehead, Header.class);
		}
		return ResultInfoUtil.setSuccessInfo(value,header.getService());
	}
	
	
	@RequestMapping(value="/getKeyAndValueByType/0", method = RequestMethod.POST)
	@ResponseBody
	public Object getKeyAndValueByType(@RequestHeader(value="mobilehead") String mobilehead,@RequestBody DictionaryDto dto) {
		List<DictionaryVo> value = this.dictionaryService.getKeyAndValueByType(dto.getPreType());
		Header header = null;
		if(null != mobilehead) {
			header = JSON.parseObject(mobilehead, Header.class);
		}
		return ResultInfoUtil.setSuccessInfo(value,header.getService());
	}
	
	
	
}
